
<?php	
function listownclient($clienttype, $salerid, $DB){
echo "<table cellspacing='1' cellpadding='1'>
<tr class='list_head'>
<td>ID</td> <td>修改</td> <td>联系方式</td> <td>姓名</td> <td>提交时间</td> <td>回收剩余天数</td><td>下次拜访时间</td>  <td>资金量(万元)</td> <td>需求</td> <td>性格</td> <td>所需开发速度</td> <td>其他开发人员</td>  <td>成交时间</td>  <td>成交金额(万)</td> <td>是否还有开发潜力</td> <td>建议谁继续开发</td> <td>预计产品</td> <td>备注</td> <td>转给其他人员</td> 
</tr>";

if($clienttype==3)
{ //black list
	$query = "SELECT id,name,submit_time,next_devtime,fund,demand,charact,devspeed,othersalers,deal_time,deal_money, addict_dev, suppose_saler,product,remark FROM client WHERE id IN (SELECT clientid FROM client_saler_rel WHERE salerid=$salerid AND state ='active' ) AND type=$clienttype";
}
else
{
	$query = "SELECT id,name,submit_time,next_devtime,fund,demand,charact,devspeed,othersalers,deal_time,deal_money, addict_dev, suppose_saler,product,remark FROM client WHERE id IN (SELECT clientid FROM client_saler_rel WHERE salerid=$salerid AND state ='active' ) AND type=$clienttype AND createid=$salerid ";
}


//echo $query;
$result = mysql_query($query,$DB);


$index = 0;
while( $myrow = mysql_fetch_row($result) )
{
	$clientid = $myrow[0];
	$name = $myrow[1];
	$submit_time = $myrow[2];
	$next_devtime = $myrow[3];
	$fund= $myrow[4];
	$demand = ClientNeedList::getItem($myrow[5]);
	$charact = ClientCharaList::getItem($myrow[6]);
	$devspeed = ClientDevSpdList::getItem($myrow[7]);
	$othersalers = $myrow[8];
	$deal_time = $myrow[9];
	$deal_money = $myrow[10];
	$addictd_dev = ($myrow[11]==0)?"否":"是";
	$suppose_saler = $myrow[12];
	$product = $myrow[13];
	$remark = $myrow[14];
	
	$current_day = date("Y-m-d");
	$submit_day = explode(" ",$submit_time);
	$submit_day = $submit_day[0];
	
	$leftday = 20- (strtotime($current_day) - strtotime($submit_day))/(3600*24);
	if($leftday<0)$leftday = "已回收";

	$index = $index+1;
	$classtype= $index%2==0?'list_eve':'list_odd';
	printf("<tr class='$classtype'> <td>%d</td>
		   		<td><a href=\"clientform1.php?clientid=%d\"><img src='../edit.png'/></a></td>
				<td><a href=\"listcontact.php?clientid=%d\" rel='facebox' ><img src='../phone.png'/></a></td>
				<td>%s</td> 
				<td>%s</td>  
				<td>%s</td>
				<td>%s</td>
				<td>%.2f</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%.2f</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>		
				<td><a href='transferclient.php?clientid=%d' rel='facebox'>T</a></td>
				</tr>\n",
			$index,$clientid,$clientid,$name,$submit_time,$leftday,$next_devtime,$fund,$demand,$charact,$devspeed,$othersalers,$deal_time,$deal_money,$addictd_dev,$suppose_saler,$product,$remark,$clientid
			);
}

echo "</table>";

}

require_once('..\\predefine.php');
//list clients transfer from other client
function listhandleclient($salerid, $DB){
echo "<table cellspacing='1' cellpadding='1' >
<tr class='list_head'>
<td>ID</td> <td>修改</td><td>联系方式</td><td>类型</td><td>姓名</td> <td>提交时间</td> <td>回收剩余天数</td><td>下次拜访时间</td>  <td>资金量(万元)</td> <td>需求</td> <td>性格</td> <td>所需开发速度</td> <td>其他开发人员</td>  <td>成交时间</td>  <td>成交金额(万)</td> <td>是否还有开发潜力</td> <td>建议谁继续开发</td> <td>预计产品</td> <td>备注</td> <td>提供者</td> 
</tr>";


$query = "SELECT id,name,submit_time,next_devtime,fund,demand,charact,devspeed,othersalers,deal_time,deal_money, addict_dev, suppose_saler,product,remark,type,createid FROM client WHERE id IN (SELECT clientid FROM client_saler_rel WHERE salerid=$salerid AND state ='active' ) AND  createid<>$salerid AND type<>3 ";
//echo $query;

//echo $query;
$result = mysql_query($query,$DB);


$index = 0;
while( $myrow = mysql_fetch_row($result) )
{
	$clientid = $myrow[0];
	$name = $myrow[1];
	$submit_time = $myrow[2];
	$next_devtime = $myrow[3];
	$fund= $myrow[4];
	$demand = ClientNeedList::getItem($myrow[5]);
	$charact = ClientCharaList::getItem($myrow[6]);
	$devspeed = ClientDevSpdList::getItem($myrow[7]);
	$othersalers = $myrow[8];
	$deal_time = $myrow[9];
	$deal_money = $myrow[10];
	$addictd_dev = ($myrow[11]==0)?"否":"是";
	$suppose_saler = $myrow[12];
	$product = $myrow[13];
	$remark = $myrow[14];
	$clienttype = $myrow[15];
	$clienttype = ClientType::getItem($clienttype);
	$createid = $myrow[16];
	
	$query = "SELECT name From saler WHERE id = $createid ";
	
	if($rowsaler = mysql_fetch_row(mysql_query($query,$DB)))
	{
		$createid = $rowsaler[0];
	}
	
	
	$current_day = date("Y-m-d");
	$submit_day = explode(" ",$submit_time);
	$submit_day = $submit_day[0];
	
	$leftday = 20- (strtotime($current_day) - strtotime($submit_day))/(3600*24);
	if($leftday<0)$leftday = "已回收";

	$index = $index+1;
	$classtype= $index%2==0?'list_eve':'list_odd';
	printf("<tr class='$classtype'> <td>%d</td>
		   		<td><a href=\"clientform1.php?clientid=%d\"><img src='../edit.png'/></a></td>
				<td><a href=\"listcontact.php?clientid=%d\" rel='facebox' ><img src='../phone.png'/></a></td>
				<td>%s</td> 
				<td>%s</td>  
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%.2f</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%.2f</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>
				<td>%s</td>		
				<td>%s</td>
				</tr>\n",
			$index,$clientid,$clientid,$clienttype,$name,$submit_time,$leftday,$next_devtime,$fund,$demand,$charact,$devspeed,$othersalers,$deal_time,$deal_money,$addictd_dev,$suppose_saler,$product,$remark,$createid
			);
}

echo "</table>";

}
?>
